package com.bingkaimedia.merchantbeta.libs;

import java.util.ArrayList;
import java.util.HashMap;

import com.bingkaimedia.merchantbeta.R;
import com.bingkaimedia.merchantbeta.app.List_Data_Semua;
import com.bingkaimedia.merchantbeta.libs_image.ImageLoader;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class LazyAdapter extends BaseAdapter {
    
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    
    public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
        vi = inflater.inflate(R.layout.item_list_lazyadapter, null);

        TextView txt_voucher_id = (TextView)vi.findViewById(R.id.txt_voucher_id); // title
        TextView txt_voucher_detail = (TextView)vi.findViewById(R.id.txt_voucher_description); // title
        TextView txt_merchant_name = (TextView)vi.findViewById(R.id.txt_merchant_name); // title
        TextView txt_merchant_category = (TextView)vi.findViewById(R.id.txt_merchant_category); // title
        TextView txt_voucher_name = (TextView)vi.findViewById(R.id.txt_voucher_name); // artist name
        TextView txt_voucher_tersedia = (TextView)vi.findViewById(R.id.txt_voucher_tersedia); // duration
        TextView txt_channel_name = (TextView)vi.findViewById(R.id.txt_channel_name); // artist name
        ImageView txt_merchant_photo=(ImageView)vi.findViewById(R.id.txt_merchant_photo); // thumb image
        
        HashMap<String, String> song = new HashMap<String, String>();
        song = data.get(position);
        
        // Setting all values in listview
        txt_voucher_id.setVisibility(View.GONE);
        
        txt_voucher_id.setText(song.get(List_Data_Semua.KEY_VOUCHER_ID));
        txt_merchant_name.setText(song.get(List_Data_Semua.KEY_MERCHANT_NAME));
        txt_channel_name.setText(song.get(List_Data_Semua.KEY_CHANNEL_NAME));
        txt_voucher_name.setText(song.get(List_Data_Semua.KEY_VOUCHER_NAME));
        txt_merchant_category.setText("Category : "+song.get(List_Data_Semua.KEY_MERCHANT_CATEGORY));
        //txt_voucher_tersedia.setText(song.get(List_Data_Semua.KEY_VOUCHER_TERSEDIA));
        //txt_voucher_detail.setText(song.get(List_Data_Semua.KEY_VOUCHER_DETAIL));
        imageLoader.DisplayImage(song.get(List_Data_Semua.KEY_MERCHANT_PHOTO), txt_merchant_photo);
        return vi;
    }
}